package com.qupeng.demo.kafka.kafkaspringbootproducer.jaas;

import org.springframework.context.annotation.Bean;
import org.springframework.kafka.security.jaas.KafkaJaasLoginModuleInitializer;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class JaasConfig {
    @Bean
    public KafkaJaasLoginModuleInitializer jaasConfig() throws IOException {
        KafkaJaasLoginModuleInitializer jaasConfig = new KafkaJaasLoginModuleInitializer();
        jaasConfig.setControlFlag(KafkaJaasLoginModuleInitializer.ControlFlag.REQUIRED);
        Map<String, String> options = new HashMap<>();
        options.put("useKeyTab", "true");
        options.put("storeKey", "true");
        options.put("keyTab", "/etc/security/keytabs/kafka_client.keytab");
        options.put("principal", "kafka-client-1@EXAMPLE.COM");
        jaasConfig.setOptions(options);
        return jaasConfig;
    }
}
